/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年5月23日
 */
package com.massyframework.beanskin.graphql.context;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import graphql.ErrorClassification;
import graphql.ErrorType;
import graphql.GraphQLError;
import graphql.language.SourceLocation;

/**
 * {@link GraphQLRuntimeException}, GraphQL运行时例外
 * @author huangkaihui
 *
 */
public class GraphQLRuntimeException extends RuntimeException 
	implements GraphQLError{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8835988566940469776L;
	
	private Map<String, Object> extensions = new HashMap<>();
	private List<Object> path;

	/**
	 * 构造方法
	 * @param errCode
	 * @param message
	 * @param cause
	 */
	public GraphQLRuntimeException(String errCode, String message, Throwable cause) {
		this(errCode, message, cause, null);
	}
	
	/**
	 * 构造方法
	 * @param errCode {@link String}, 代码
	 * @param message {@link String}, 消息
	 * @param path {@link List}
	 * @param locations {@link List}
	 */
	public GraphQLRuntimeException(String errCode, String message, Throwable cause, List<Object> path) {
		super(message, cause);
		this.extensions.put("errorCode", errCode == null ? "99999": errCode);
		this.path = path;
	}

	@Override
	public Map<String, Object> getExtensions() {
		return extensions;
	}
	
	@Override
	public List<Object> getPath() {
		return this.path;
	}

	@Override
	public List<SourceLocation> getLocations() {
		return null;
	}

	@Override
	public ErrorClassification getErrorType() {
		return ErrorType.DataFetchingException;
	}
}
